﻿using D.ATN.Extensions;
using D.ATN.Models;
using System.Data;
using D.ATN.Dto;
using D.ATN.UIUitl;
using D.ATN.HttpUtil;
using D.ATN.Events;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using System.Text;
using NLog;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Collections.Generic;
using System;
using System.Web;
using D.ATN.NLogsUtil;
using System.Linq;
using System.Threading.Tasks;

namespace D.ATN
{
    public partial class FrmSpcCheck : Form
    {

        public FrmSpcCheck()
        {
            InitializeComponent();
            this.dgvProcess.SetGridDataViewStyle();
            this.cboLds.SelectedValueChanged += CboLds_SelectedValueChanged;
            this.dgvProcess.CellContentClick += dgvProcess_CellContentClick;
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void FrmSpcCheck_Load(object sender, EventArgs e)
        {
            this.LoadUiData();
            await LoadEnvAsync();
            await LoadDcItemAsync();
        }

        private void LoadUiData()
        {
            cboLds.Items.Clear();
            cboLds.Items.Add("RT");
            cboLds.Items.Add("NonRT");
            cboLds.Items.Add("NonLot");

            this.cboContinueUni.Items.Clear();
            this.cboContinueUni.Items.Add("分钟");
            this.cboContinueUni.Items.Add("次");
            this.cboContinueUni.Text = "分钟";

            this.txtJson.Text = httpJson;
        }
        private string httpJson = @"
[{
	""traceId"": null,
	""batchInfo"": ""BatchInfo"",
	""batchLot"": ""BatchInfo"",
	""batchSize"": ""99999"",
	""batchProductID"": ""BatchProductID"",
	""jobNames"": [{CHARTIDS}],
    ""receiveTime"": ""{MEASUREMENTTIME}"",
	""fabID"": ""{FABID}"",
	""areaID"": ""{AREAID}"",
	""lotId"": ""P00005.19"",
	""flowSeq"": ""013400"",
	""batchIDs"": null,
	""waferIDs"": null,
	""routeID"": ""DE2011"",
	""routeSeq"": ""1000"",
	""operationSeq"": ""013400"",
	""prod_6"": ""91"",
	""prod_7"": """",
	""prod_8"": """",
	""prod_9"": """",
	""prod_10"": """",
	""batchFlag"": ""N"",
	""lotsInBatch"": null,
	""lotType"": ""PE"",
	""customerLot"": """",
	""recipeID"": ""GMIC_SAC_S11"",
	""location"": null,
	""technologyID"": """",
	""productId"": ""{PRODUCT}"",
	""prod_1"": ""ETCH\\OXIDE\\"",
	""prod_2"": ""TESTPORCESS"",
	""prod_3"": ""YCGOD012PORCT"",
	""prod_4"": """",
	""customer"": ""*"",
	""device"": """",
	""operatorID"": ""WANGQ"",
	""materialID"": """",
	""operationNumber"": ""WWDUMC2"",
	""realOperationNumber"": ""1000#$#DE020171"",
	""dcopNo"": null,
	""reworkCount"": 0,
	""equipmentId"": ""LMPFM01S"",
	""completionDate"": ""0001-01-01 00:00:00"",
	""loadProcessDate"": ""0001-01-01 00:00:00"",
	""tartget"": 500.0,
	""usl"": 1000.0,
	""lsl"": 300.0,
	""subGroupSize"": null,
	""monitorGroupId"": """",
	""lotSetSeq"": """",
	""headerID"": """",
    ""jobComplete"": -1,
	""processDataInfos"": [],
	""p1Time"": null,
	""p1EquipmentId"": null,
    ""excelFlag"": null,
	""edcType"": """",
	""chamberID"": null,
    ""p_Infos"": [{
		""routeSeq"": null,
		""route"": ""D1001"",
		""operation"": ""E42435"",
		""operationSeq"": null,
		""recipe"": ""2"",
		""equipment"": ""22"",
		""flowSeq"": null,
		""pTime"": ""{PROCESSTIME}""
	}, {
		""routeSeq"": null,
		""route"": null,
		""operation"": ""E01068"",
		""operationSeq"": null,
		""recipe"": ""11"",
		""equipment"": ""ACC01"",
		""flowSeq"": null,
		""pTime"": ""{PROCESSTIME}""
	}, {
		""routeSeq"": null,
		""route"": """",
		""operation"": ""YTHZXK6"",
		""operationSeq"": null,
		""recipe"": ""*"",
		""equipment"": ""ACC01"",
		""flowSeq"": null,
		""pTime"": ""{PROCESSTIME}""
	}]
}]";
        private async void LoadData()
        {
            await LoadFabAsync();
            // 加载MES || SPC的数据
            await LoadDcItemAsync();
            await LoadProcessEntityAsync();
        }

        #region 加载数据 

        private async Task LoadFabAsync()
        {
            var fabList = await ServiceLocator.SpcFreeSql.Select<SPCFabEntity>().ToListAsync();
            this.cboFab.DisplayMember = "fab_id";
            this.cboFab.DataSource = fabList;
        }

        private List<EnvSettingEntity> envSettingEntities = null;
        private async Task LoadEnvAsync()
        {
            envSettingEntities = await ServiceLocator.MySqllite.Select<EnvSettingEntity>().ToListAsync();
            this.cboEnv.DisplayMember = "Name";
            this.cboEnv.DataSource = envSettingEntities;
        }

        private async void CboLds_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboLds.SelectedItem != null)
            {
                await LoadAreaAsync(cboLds.SelectedItem.ToString());
            }
        }

        private List<SPCDeparmentEntity> sPCDeparmentEntities = null;
        private async Task LoadAreaAsync(string area_type)
        {
            sPCDeparmentEntities = await ServiceLocator.SpcFreeSql.Select<SPCDeparmentEntity>().Where(m => m.area_type == area_type).ToListAsync();
            this.cboDeparment.DisplayMember = "area_id";
            this.cboDeparment.DataSource = sPCDeparmentEntities;
        }

        private async Task LoadDcItemAsync()
        {
            txtKeyDcItem.Text = "";
            checkMESDcitem.Items.Clear();

            //var dcItemList = await ServiceLocator.MesFreeSql.Select<MESDcItemEntity>().Distinct().ToListAsync();
            //var array = dcItemList.Select(m => m.DCITEM_NAME).ToArray();
            checkMESDcitem.Items.AddRange(ServiceLocator.DcItemList.ToArray());
        }

        #endregion

        #region 保存模拟发送配置


        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var envSettingEntity = this.cboEnv.SelectedItem as EnvSettingEntity;
                if (envSettingEntity == null)
                {
                    MessageBox.Show("请选择环境！"); return;
                }
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    MessageBox.Show("请输入名称！"); return;
                }

                if (checkRandom.Checked && txtLower.Value == 0 && txtUpper.Value == 0)
                {
                    MessageBox.Show("请填写随机生成原始值区间！"); return;
                }
                if (checkRandom.Checked && txtLower.Value >= txtUpper.Value)
                {
                    MessageBox.Show("随机生成原始值区间有误！"); return;
                }

                var msg = txtJson.Text;

                var processEntity = new ProcessEntity()
                {
                    Name = txtName.Text,
                    BasicInfo = msg,
                    DcItemCount = checkMESDcitem.CheckedItems.Count,
                    EvnName = envSettingEntity.Name,
                    RawDataCount = (int)txtRawDataCount.Value,
                    RawDataRandom = checkRandom.Checked,
                    ContinueUni = cboContinueUni.SelectedItem.ToString(),
                    ContinueCount = (int)txtContinueCount.Value,
                    UserCount = (int)txtUserCount.Value,
                    WaferCount = (int)txtWaferCount.Value,
                    Second = txtSecond.Value,
                    SecondCount = (int)txtSecondCount.Value,
                    Lower = (int)txtLower.Value,
                    Upper = (int)txtUpper.Value,
                    RuleOOCoos = txtRuleOOCOOS.Value,
                    LdsName = cboLds.SelectedText
                };

                //var random = new Random();
                //var chamberTmplate = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";

                //if (checkDataCollection.Checked && !string.IsNullOrEmpty(txtSpcChamber.Text.Trim()))
                //{
                //    processEntity.Chambers = txtSpcChamber.Text.Trim();
                //}
                //else if (!checkDataCollection.Checked && checkChamber.CheckedItems.Count > 0)
                //{
                //    for (int i = 0; i < checkChamber.CheckedItems.Count; i++)
                //    {
                //        processEntity.Chambers += checkChamber.CheckedItems[i].ToString() + ",";

                //        var chamberEntity = chamebrList.Where(m => m.CHAMBER_ID == checkChamber.CheckedItems[i].ToString()).FirstOrDefault();
                //        if (chamberEntity != null)
                //        {
                //            StringBuilder sb = new StringBuilder(chamberTmplate);
                //            sb[chamberEntity.SEQ] = '_';
                //            sb = sb.Replace("_", chamberEntity.REPRESENTATION_ID);
                //            processEntity.ChamebrStrs += sb.ToString() + ",";
                //        }
                //    }
                //}

                if (processEntity.Chambers != null)
                {
                    if (processEntity.Chambers.Length > 0)
                    {
                        processEntity.Chambers = processEntity.Chambers.Trim(',');
                    }
                }


                for (int i = 0; i < checkMESDcitem.CheckedItems.Count; i++)
                {
                    processEntity.DcItems += checkMESDcitem.CheckedItems[i].ToString() + ",";
                }
                if (processEntity.DcItems.Length > 0)
                {
                    processEntity.DcItems = processEntity.DcItems.Trim(',');
                }

                var process = await ServiceLocator.MySqllite.Select<ProcessEntity>().Where(m => m.Name == processEntity.Name).FirstAsync();
                if (process != null)
                {// 修改
                    processEntity.Id = process.Id;
                    var updateRes = await ServiceLocator.MySqllite.Update<ProcessEntity>().SetSource(processEntity).ExecuteAffrowsAsync();
                    if (updateRes > 0)
                    {
                        MessageBox.Show("修改成功");
                        await this.LoadProcessEntityAsync();
                    }
                    else
                    {
                        MessageBox.Show("修改失败");
                    }
                }
                else
                {// 新增
                    var insertRes = await ServiceLocator.MySqllite.Insert<ProcessEntity>(processEntity).ExecuteAffrowsAsync();
                    if (insertRes > 0)
                    {
                        MessageBox.Show("新增成功");
                        await this.LoadProcessEntityAsync();
                    }
                    else
                    {
                        MessageBox.Show("新增失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"系统异常【{ex.Message}】");
            }
        }

        private List<ProcessEntity> processEntities = new List<ProcessEntity>();
        /// <summary>
        /// 加载表格数据
        /// </summary>
        /// <returns></returns>
        private async Task LoadProcessEntityAsync()
        {
            processEntities = await ServiceLocator.MySqllite.Queryable<ProcessEntity>().ToListAsync();
            this.dgvProcess.DataSource = processEntities;
        }

        private void dgvProcess_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dgvProcess.Columns[e.ColumnIndex].Name != "Delete")
            {
                var id = dgvProcess.Rows[e.RowIndex].Cells["Id"].Value?.ToString();
                var processEntity = processEntities.Where(m => m.Id == int.Parse(id)).FirstOrDefault();
                txtName.Text = processEntity.Name;
                txtJson.Text = processEntity.BasicInfo;

                cboEnv.SelectedItem = envSettingEntities.Where(m => m.Name == processEntity.EvnName).FirstOrDefault();
                txtRawDataCount.Value = processEntity.RawDataCount;
                checkRandom.Checked = processEntity.RawDataRandom;
                txtContinueCount.Value = processEntity.ContinueCount;
                cboContinueUni.SelectedItem = processEntity.ContinueUni;
                txtUserCount.Value = processEntity.UserCount;
                txtWaferCount.Value = processEntity.WaferCount;
                txtSecondCount.Value = processEntity.SecondCount;

                if (processEntity.Second == null || processEntity.Second <= 0)
                {
                    txtSecond.Value = (decimal)0.1;
                }
                else
                {
                    txtSecond.Value = processEntity.Second;
                }

                if (checkRandom.Checked)
                {
                    txtLower.Value = processEntity.Lower;
                    txtUpper.Value = processEntity.Upper;
                }

                if (processEntity.RuleOOCoos != null)
                {
                    txtRuleOOCOOS.Value = processEntity.RuleOOCoos;
                }

                if (processEntity.DcItems != null)
                {
                    txtKeyDcItem.Text = "";

                    txtKeyDcItem.Enabled = false;
                    checkMESDcitem.Enabled = true;
                    var dcItems = processEntity.DcItems.Split(',').ToList();
                    for (int i = 0; i < checkMESDcitem.Items.Count; i++)
                    {
                        if (dcItems.Any(m => m == checkMESDcitem.Items[i].ToString()))
                        {
                            checkMESDcitem.SetItemChecked(i, true);
                        }
                    }

                    lblDcitemCount.Text = $"总监控数量：{dcItems.Count}个";
                }
            }
        }

        /// <summary>
        /// 点击删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void dgvProcess_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (this.dgvProcess.Columns[e.ColumnIndex].Name == "Delete")
                {
                    //获取所在行的值
                    var id = int.Parse(dgvProcess.Rows[e.RowIndex].Cells["Id"].Value.ToString());
                    // 删除
                    var deleteRes = await ServiceLocator.MySqllite.Delete<ProcessEntity>().Where(m => m.Id == id).ExecuteAffrowsAsync();
                    if (deleteRes > 0)
                    {
                        MessageBox.Show("删除成功");
                        await this.LoadProcessEntityAsync();
                    }
                    else
                    {
                        MessageBox.Show("删除失败");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// 选择dc item后计数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkMESDcitem_ItemCheck(object sender, ItemCheckEventArgs e)
        {

            var number = 0;
            if (checkMESDcitem.CheckedItems != null)
            {
                number = checkMESDcitem.CheckedItems.Count;
            }

            if (e.NewValue == CheckState.Checked)
            {
                number += 1;
            }
            if (e.NewValue == CheckState.Unchecked)
            {
                if (number - 1 < 0)
                {
                    number = 0;
                }
            }

            if (!string.IsNullOrEmpty(txtKeyDcItem.Text))
            {
                number = 1;
            }
            lblDcitemCount.Text = $"总监控数量：{number}个";
        }
        #endregion

        #region 模拟发送

        /// <summary>
        /// 模拟发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                var envSettingEntity = this.cboEnv.SelectedItem as EnvSettingEntity;
                if (envSettingEntity == null)
                {
                    MessageBox.Show("请选择环境！"); return;
                }
                string message = BuildHttpMessage();
                // 发送数据
                var url = $"http://{envSettingEntity.RTIp}:{envSettingEntity.RTPort}/{ServiceLocator.SPC_RT_CHECK_URL}";
                var res = await HttpClientHelper.HttpPostAsync<SpcHttpCheckResponseDto>(url, ServiceLocator.TimeOut, message);
                var result = JsonConvert.SerializeObject(res);
                if (res.code != 200)
                {
                    MessageBox.Show($"Error-{res.code}-{res.message}");
                }
                else
                {

                    if (res.code == 0000)
                    {
                        MessageBox.Show($"{res.code}-Success");
                    }
                    else if (res.code == 0001)
                    {
                        MessageBox.Show($"{res.code}-FUR没有按约定送Waferposition");
                    }
                    else if (res.code == 0002)
                    {
                        MessageBox.Show($"{res.code}-多个DCSID的Spec不一致");
                    }
                    else if (res.code == 1500)
                    {
                        MessageBox.Show($"{res.code}-系统异常");
                    }
                    else if (res.code == 1511)
                    {
                        MessageBox.Show($"{res.code}-没有匹配到Chart");
                    }
                    else if (res.code == 1512)
                    {
                        MessageBox.Show($"{res.code}-Spec跟Control的Limit校验失败");
                    }
                    else
                    {
                        MessageBox.Show($"Error-{res.code}-{res.message}");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"系统异常：【{ex.Message}】");
            }
        }
        private string BuildHttpMessage()
        {
            // 基础数据
            var basicInfo = txtJson.Text;
            var fabId = (cboFab.SelectedItem as SPCFabEntity).fab_id;
            string areaId = (cboDeparment.SelectedItem as SPCDeparmentEntity).area_id;
            // 设置加工时间、量测时间
            var measurementTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss");
            var processTimestamp = DateTime.Now.AddHours(-2).ToString("yyyy-MM-dd HH.mm.ss");
            basicInfo = basicInfo.Replace("{MEASUREMENTTIME}", measurementTimestamp)
                                 .Replace("{PROCESSTIME}", processTimestamp)
                                 .Replace("{FABID}", fabId)
                                 .Replace("{AREAID}", areaId);

            // 数量
            var dcItemCount = checkMESDcitem.CheckedItems.Count > 0 ? checkMESDcitem.CheckedItems.Count : 1;
            var waferCount = txtWaferCount.Value;
            var rawDataCount = txtRawDataCount.Value;

            var lower = (int)txtLower.Value;
            var upper = (int)txtUpper.Value;

            //  违规率超过 30%  =  总量测点：3监控参数 * 3片数 * 17个点=153个点  * 0.3 = 45个样点违规：违规的点的数量
            var totalOOCOOSRawCount = rawDataCount * waferCount * txtRuleOOCOOS.Value;


            var chartIds = new StringBuilder();
            var random = new Random();
            var dcItems = new StringBuilder();
            var oocoosCount = 0;

            basicInfo = basicInfo.Replace("{PRODUCT}", ServiceLocator.ProductList[random.Next(ServiceLocator.ProductList.Count)]);

            // 监控参数
            for (int a = 1; a <= dcItemCount; a++)
            {
                if (checkMESDcitem.CheckedItems.Count > 0)
                {
                    chartIds.AppendLine("\"" + checkMESDcitem.CheckedItems[a - 1] + "\",");
                }
                else
                {
                    chartIds.AppendLine("\"" + txtKeyDcItem.Text.Trim() + "\",");
                }

                var chamberId = ServiceLocator.ChamberList[random.Next(ServiceLocator.ChamberList.Count)];
                // wafer
                for (int b = 1; b <= waferCount; b++)
                {
                    // 量测点
                    for (int c = 1; c <= rawDataCount; c++)
                    {
                        dcItems.AppendLine("{");

                        if (checkMESDcitem.CheckedItems.Count > 0)
                        {
                            dcItems.AppendLine("\"dataCollectionItemName\": \"" + checkMESDcitem.CheckedItems[a - 1] + "\",");
                        }
                        else
                        {
                            dcItems.AppendLine("\"dataCollectionItemName\": \"" + txtKeyDcItem.Text.Trim() + "\",");
                        }

                        // 注意:不需要引号
                        if (checkRandom.Checked)
                        {
                            if (oocoosCount < totalOOCOOSRawCount)
                            {
                                // 生成违规的数据
                                if (c % 3 == 0)
                                {
                                    dcItems.AppendLine("\"dataValue\": " + random.Next(upper, random.Next(upper, upper + 50)) + ",");
                                }
                                else
                                {
                                    dcItems.AppendLine("\"dataValue\": " + random.Next(random.Next(lower - 50, lower), lower) + ",");
                                }
                                oocoosCount++;
                            }
                            else
                            {
                                dcItems.AppendLine("\"dataValue\": " + random.Next(lower, upper) + ",");
                            }
                        }
                        else
                        {
                            dcItems.AppendLine("\"dataValue\": " + (700 + random.Next(1, 99)) + ",");
                        }

                        dcItems.AppendLine("\"dataCollectionMode\": \"\",");
                        dcItems.AppendLine("\"dataCollectionUnit\": \"\",");
                        dcItems.AppendLine("\"dataType\": \"\",");
                        dcItems.AppendLine("\"itemType\": \"\",");
                        dcItems.AppendLine("\"measurementType\":\"\",");
                        dcItems.AppendLine("\"waferId\": \"PP000013-" + b + "\",");
                        dcItems.AppendLine("\"lotId\": \"\",");
                        dcItems.AppendLine("\"siteID\": \"#" + c + "\",");
                        dcItems.AppendLine("\"bumpID\": \"\",");
                        dcItems.AppendLine("\"waferPosition\": \"" + b + "\",");
                        dcItems.AppendLine("\"sitePosition\": \"" + c + "\",");
                        dcItems.AppendLine("\"bumpPosition\":  \"\",");
                        dcItems.AppendLine("\"historyRequiredFlag\":  \"" + false + "\",");
                        dcItems.AppendLine("\"calculationType\":  \"\",");
                        dcItems.AppendLine("\"calculationExpression\": \"\",");
                        dcItems.AppendLine("\"targetValue\":  \"\",");
                        dcItems.AppendLine("\"specCheckResult\":  \"\",");
                        dcItems.AppendLine("\"actionCode\":  \"\",");
                        dcItems.AppendLine("\"siInfo\": null,");
                        dcItems.AppendLine("\"defectCodeList\": [],");
                        dcItems.AppendLine("\"defectCountList\": [],");
                        dcItems.AppendLine("\"chamberID\":  \"" + chamberId + "\"");
                        dcItems.AppendLine(" },");
                    }
                }
            }

            basicInfo = basicInfo.Replace("{CHARTIDS}", chartIds.ToString().TrimEnd(','));
            var message = basicInfo.Insert(basicInfo.Length - 2, $",\"dcItems\": [{dcItems.ToString().TrimEnd(',')}]");
            return message;
        }


        #endregion

        #region 更换环境

        private async void btnConn_Click(object sender, EventArgs e)
        {
            try
            {
                var envSettingEntity = this.cboEnv.SelectedItem as EnvSettingEntity;
                if (envSettingEntity != null)
                {
                    var initRes = await ResetFreeSql(envSettingEntity);
                    if (initRes == 0)
                    {// 成功、重新加载所有数据 
                        LoadData();
                        this.btnConn.Enabled = false;
                    }
                    else if (initRes == 1)
                    {// spc连接失败
                        MessageBox.Show("SPC数据库连接异常");
                    }
                    else if (initRes == 2)
                    {// mes连接失败
                        MessageBox.Show("MES数据库连接异常");
                    }
                    else
                    {// -1 异常
                        MessageBox.Show("数据库连接异常");
                    }
                }
                else
                {
                    MessageBox.Show("请选择数据库链接");
                }
            }
            catch (Exception ex)
            {
                NLogHelper.Error(ex.Message);
                MessageBox.Show("数据库连接异常");
            }
        }
        private void cboEnv_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.btnConn.Enabled = true;
        }
        public async Task<int> ResetFreeSql(EnvSettingEntity env)
        {
            // 拼接连接字符串(service Name 不行)
            var spcConnStr = string.Empty;
            var mesConnStr = string.Empty;

            if (!string.IsNullOrEmpty(env.SPCIp))
            {
                spcConnStr = $"Host={env.SPCIp}:{env.SPCPort};database={env.SPCDataBase};user id={env.SPCAccount};password={env.SPCPwd};searchpath={env.SPCSearchPath};Maximum Pool Size=500;";
            }

            if (!string.IsNullOrEmpty(env.MESIp))
            {
                mesConnStr = $"Host={env.MESIp}:{env.MESPort};database={env.MESDataBase};user id={env.MESAccount};password={env.MESPwd};searchpath={env.MESSearchPath};Maximum Pool Size=500;";
            }

            // 初始化DB
            return await OrmFactory.AddFreeSql(env.Name, mesConnStr, spcConnStr);
        }
        #endregion

        #region 消息详情

        private string result = string.Empty;
        private async void btnMsgDetail_Click(object sender, EventArgs e)
        {
            //FrmSpcCheckMessage frmSpcCheckMessage = new FrmSpcCheckMessage(message, result);
            //frmSpcCheckMessage.ShowDialog();
        }
        #endregion

        private void checkMESDcitem_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblDcitemCount.Text = $"总监控数量：{checkMESDcitem.CheckedItems.Count}个";
        }
    }
}
